/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package horde.internalResources.editor;

import horde.internalResources.dictionaries.dictionary;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Administrador
 */
public class AutomatonPanel extends JPanel {

    private JLabel initialStateName;
    private JComboBox initialStateChooser;
    private JTable statesTable;
    private DefaultTableModel statesTableModel;
    private JScrollPane scroll;

    public AutomatonPanel () {
        super();
        init();
    }

    private void init () {
        setLayout (new BorderLayout());
        initialStateName = new JLabel (dictionary.getString("words.init"));
        initialStateChooser = new JComboBox();
        initialStateChooser.setPreferredSize(new Dimension(300,30));
        statesTableModel = new DefaultTableModel(){
            @Override
            public Class getColumnClass(int columnIndex) {
                return FSMStatePanel.class;
            }
        };
        statesTableModel.addColumn(dictionary.getString("words.states"));
        statesTable = new JTable();
        statesTable.setDefaultRenderer(FSMStatePanel.class, new FSMStatePanel());
        statesTable.setDefaultEditor(FSMStatePanel.class, new FSMStatePanel());
        statesTable.setModel(statesTableModel);
        scroll = new JScrollPane(statesTable);
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        JPanel namePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        namePanel.add (initialStateName);
        namePanel.add (initialStateChooser);
        add (namePanel, BorderLayout.PAGE_START);
        add (scroll, BorderLayout.CENTER);
        statesTable.setRowHeight(150);
    }

    public void newState () {
        FSMStatePanel [] data = {new FSMStatePanel()};
        statesTableModel.addRow(data);
    }

    public void newStateDemo () {
        FSMStatePanel [] data = {new FSMStatePanel(true)};
        statesTableModel.addRow(data);
    }

}
